#include "XSerialGenerator.h"
#include "XStringHelpers.h"

namespace Xts
{
	namespace Util
	{
		XSerialGenerator::XSerialGenerator(void)
			:x_startNum(0), x_prefix(), x_accmValue(0)
		{
		}

		XSerialGenerator::XSerialGenerator(const ::Ice::Long& startNo, const ::std::string& prefix)
			: x_startNum(startNo), x_prefix(prefix), x_accmValue(0)
		{
		}

		XSerialGenerator::~XSerialGenerator(void)
		{
		}

		::Ice::Long XSerialGenerator::SerialNum()
		{ 
			return x_startNum + x_accmValue++; 
		}

		::std::string XSerialGenerator::SerialStr()
		{
			return x_prefix + Ltos(SerialNum());
		}

		::Ice::Long XSerialGenerator::TreadSafeSerialNum()
		{
			::IceUtil::Mutex::Lock m(x_mutex);
			return SerialNum();
		}

		::std::string XSerialGenerator::TreadSafeSerialStr()
		{
			::IceUtil::Mutex::Lock m(x_mutex);
			return SerialStr();
		}
	}
} 

